/**
 *
 */
package net.haroeris.wh40kcampaign.dao.impl;

import java.util.Collection;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

import net.haroeris.wh40kcampaign.beans.po.Player;
import net.haroeris.wh40kcampaign.dao.PlayerDao;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author user
 *
 */
@Repository("playerDao")
@Transactional
public class PlayerDaoImpl implements PlayerDao {

    @PersistenceContext
    private EntityManager entityManager;


    /* (non-Javadoc)
     * @see net.haroeris.wh40kcampaign.dao.PlayerDao#getAllPlayers()
     */
    public Collection<Player> getAllPlayers() {
        TypedQuery<Player> thisQuery= entityManager.createNamedQuery( Player.QUERY_FINDALL, Player.class);
        return thisQuery.getResultList();
    }


    public Player getPlayerByUsername(String username) {
        Player thisPlayer= entityManager.find(Player.class, username);
        return thisPlayer;
    }
}